<?php
// 本类由系统自动生成，仅供测试用途
class ReplyAction extends CommonAction {

	public function index(){
		$profile_id= $_SESSION['profile_id'];
		$this->display();
	}

	/**
	 * 进入关注时候消息设置
	 */
	function queryFocus(){
		$profile_id= $_SESSION['profile_id'];
		$db=D("Graphic");
		$this->graphicList=$db->relation(true)->where("create_user_id =%d",$profile_id)->select();
		$this->profile = M("profile")->where(array('id' =>$profile_id))->find();
		
		$this->display();
	}
	/**
	 * 进入再次关注时候消息设置
	 */
	function queryReFocus(){
		$profile_id= $_SESSION['profile_id'];
		
		$db=D("Graphic");
		$this->graphicList=$db->relation(true)->where("create_user_id =%d",$profile_id)->select();
		$this->profile = M("profile")->where(array('id' =>$profile_id))->find();
		
// 		p($this->profile );die;
		$this->display();
	}
	
	/**
	 * 进入位置消息回复设置
	 */
	function queryLatLng(){
		$profile_id= $_SESSION['profile_id'];
	
		$db=D("Graphic");
		$this->graphicList=$db->relation(true)->where("create_user_id =%d",$profile_id)->select();
		$this->profile = M("profile")->where(array('id' =>$profile_id))->find();
	
		$this->display();
	}
	
	/**
	 * 进入自动消息回复设置
	 */
	function queryAuto(){
		$profile_id= $_SESSION['profile_id']; 
		
		$db=D("Graphic");
		$this->graphicList=$db->relation(true)->where("create_user_id =%d",$profile_id)->select();
		$this->profile = M("profile")->where(array('id' =>$profile_id))->find();
		
		$this->display();
	}
	
	/**
	 * 进入订阅退订设置
	 */
	function querySubscribeOrNot(){
		$profile_id= $_SESSION['profile_id'];
	
		$db=D("Graphic");
		$this->graphicList=$db->relation(true)->where("create_user_id =%d",$profile_id)->select();
		$this->profile = M("profile")->where(array('id' =>$profile_id))->find();
	
		$this->display();
	}
	/**
	 * 进入关键词回复设置
	 */
	function queryKeyword(){
		$profile_id= $_SESSION['profile_id'];
		$this->display();
	}
	
	function queryRuleList(){
		$profile_id= $_SESSION['profile_id'];
		
		$db=D("Graphic");
		$this->graphics=$db->relation(true)->where("create_user_id =%d",$profile_id)->select();
		$arr=M("private_rule")->select();
		
		foreach($arr as &$a){
		    if(isset($a["keyword"])){
				$kw=$a["keyword"];
				$ks=split("#",$kw);
				$a["keywordList"]=array_filter($ks);
			}
		}
		$this->ruleList=$arr;
		
		$this->display();
	}
	
	/**
	 * 保存首次关注回复内容
	 */
	function updateFollowReply(){
		$profile_id= $_SESSION['profile_id'];
		$attrValue=I("attrValue");
		$data["followReply"]=$attrValue;
		M("Profile")->where("id=".$profile_id)->save($data);
		outSuccess("ok");
	}
	
	/**
	 * 保存再次次关注回复内容
	 */
	function updateReFollowReply(){
		$profile_id= $_SESSION['profile_id'];
		$attrValue=I("attrValue");
		$data["reFollowReply"]=$attrValue;
		M("Profile")->where("id=".$profile_id)->save($data);
		outSuccess("ok");
	}
	
	/**
	 * 保存自动回复内容
	 */
	function updateAutoReply(){
		$profile_id= $_SESSION['profile_id'];
		$attrValue=I("attrValue");
		$data["messageReply"]=$attrValue;
		M("Profile")->where("id=".$profile_id)->save($data);
		outSuccess("ok");
	}
	
	/**
	 * 保存位置信息回复内容
	 */
	function updateLocationReply(){
		$profile_id= $_SESSION['profile_id'];
		$attrValue=I("attrValue");
		$data["locationReply"]=$attrValue;
		M("Profile")->where("id=".$profile_id)->save($data);
		outSuccess("ok");
	}
	
	/**
	 * 订阅取消订阅
	 */
	function updateSubOrNotReply(){
		$profile_id= $_SESSION['profile_id'];
		
		$unfollowCallback=I("unfollowCallback");
		$followCallback=I("followCallback");
		$data["followCallback"]=$followCallback;
		$data["unfollowCallback"]=$unfollowCallback;
		M("Profile")->where("id=".$profile_id)->save($data);
		outSuccess("ok");
	}
	
	/**
	 * 保存自动回复规则
	 */
	function  saveRule(){
		$id=I("id",0);
		$type=I("type");
		$name=I("name");
		$keyword=I("keyword");
		$context=I("context");
		//$date["id"]=$id;
		$date["type"]=$type;
		$date["name"]=$name;
		$date["keyword"]=$keyword;
		$date["context"]=$context;
		if($id==0){
			M("private_rule")->save($date);
		}else{
			M("private_rule")->where("id=".$id)->save($date);
		}
		outSuccess("ok");
	}
	
	/**
	 * 删除规则
	 */
	function deleteRule(){
		$id=I("id",0);
		if($id==0){
			outError("error");
		}else{
			M("private_rule")->where("id=".$id)->delete();
			outSuccess("success");
		}
	}
}